package com.intelligent.system.auth.controller;

import com.intelligent.system.auth.dto.*;
import com.intelligent.system.auth.dto.UserRoleDTO;
import com.intelligent.system.auth.service.IUserService;
import com.intelligent.system.common.response.ResultDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "用户管理")
@RestController
@RequestMapping("/api/user")
@Validated
public class UserController {

    @Resource
    private IUserService userService;

    @ApiOperation("获取用户详情")
    @GetMapping("/{id}")
    public ResultDO<UserDTO> getUserInfo(
            @ApiParam("用户ID") @PathVariable("id") @Valid Long id) {
        return userService.getUserById(id);
    }

    @ApiOperation("获取用户列表")
    @PostMapping("/list")
    public ResultDO<?> getUserList(
            @ApiParam("查询参数") @RequestBody @Valid UserQueryDTO param) {
        return userService.getUserList(param);
    }

    @ApiOperation("新增用户")
    @PostMapping("/add")
    public ResultDO<?> addUser(
            @ApiParam("用户信息") @RequestBody @Valid UserDTO param) {
        return userService.addUser(param);
    }

    @ApiOperation("修改用户")
    @PostMapping("/update")
    public ResultDO<?> updateUser(
            @ApiParam("用户信息") @RequestBody @Valid UserDTO param) {
        return userService.updateUser(param);
    }

    @ApiOperation("修改用户状态")
    @PostMapping("/status")
    public ResultDO<?> updateUserStatus(
            @ApiParam("状态修改参数") @RequestBody @Valid UserStatusDTO param) {
        return userService.updateUserStatus(param.getUserId(), param.getStatus());
    }

    @ApiOperation("删除用户")
    @PostMapping("/delete")
    public ResultDO<?> deleteUser(
            @ApiParam("用户ID") @RequestBody @Valid UserIdDTO param) {
        return userService.deleteUserById(param.getUserId());
    }

    /*@ApiOperation("重置密码")
    @PostMapping("/resetPwd")
    public ResultDO<?> resetPassword(
            @ApiParam("密码重置参数") @RequestBody @Valid UserPasswordDTO param) {
        return userService.resetPassword(param.getUserId(), param.getNewPassword());
    }

    @ApiOperation("修改密码")
    @PostMapping("/updatePwd")
    public ResultDO<?> updatePassword(
            @ApiParam("密码修改参数") @RequestBody @Valid UserPasswordDTO param) {
        return userService.updatePassword(param.getUserId(), param.getOldPassword(), param.getNewPassword());
    }*/

    @ApiOperation("分配角色")
    @PostMapping("/assignRole")
    public ResultDO<?> assignRole(
            @ApiParam("角色分配参数") @RequestBody @Valid UserRoleDTO param) {
        return userService.assignRole(param.getUserId(), param.getRoleIds());
    }
} 